package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import com.sky.vo.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * PROJECT_NAME: sky-take-out
 * NAME: OrdersController
 *
 * @AUTHOR: zhang
 * DATE: 2023/12/18
 * DESCRIPTION :
 */
@Slf4j
@Api(tags = "B端-订单信息表现层接口") //@Api:用户描述类的相关信息
@RestController("adminOrdersController")
@RequestMapping("/admin/order")
public class OrdersController {
    @Resource
    private OrdersService ordersService;

    @ApiOperation("订单搜索")
    @GetMapping("/conditionSearch")
    public Result<PageResult> ordersSearch(OrdersPageQueryDTO pageQueryDTO){
        log.info("【订单搜索】{}",pageQueryDTO);
        PageResult result = ordersService.ordersSearch(pageQueryDTO);
        return Result.success(result);
    }

    /**
     * 不同订单状态统计
     * @return
     */
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> getOrdersStatusNum(){
        OrderStatisticsVO orderStatisticsVO = ordersService.getOrdersStatusNum();
        return Result.success(orderStatisticsVO);
    }


    @ApiOperation("查看订单详情")
    @GetMapping("/details/{id}")
    public Result<OrderVO> selectOrderDetails(@PathVariable Long id){
        log.info("【查看订单详情】订单id：{}",id);
        OrderVO orderVO = ordersService.selectOrderDetails(id);
        return Result.success(orderVO);
    }

    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result confirmOrder(@RequestBody Orders orders){
        log.info("【接单】订单：{}",orders);
        ordersService.confirmOrder(orders);
        return Result.success();
    }

    @ApiOperation("拒单")
    @PutMapping("rejection")
    public Result cancelOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        log.info("【拒绝】订单：{}",ordersRejectionDTO);
        ordersService.cancelOrder(ordersRejectionDTO);
        return Result.success();
    }
    @ApiOperation("取消订单")
    @PutMapping("cancel")
    public Result cancelOrders(@RequestBody OrdersCancelDTO ordersCancelDTO){
        log.info("【取消】订单：{}",ordersCancelDTO);
        ordersService.cancelOrders(ordersCancelDTO);
        return Result.success();
    }

    @ApiOperation("派送订单")
    @PutMapping("/delivery/{id}")
    public Result deliveryOrder(@PathVariable Long id){
        log.info("【派送订单】，订单id{}",id);
        ordersService.deliveryOrders(id);
        return Result.success();
    }

    @ApiOperation("完成订单")
    @PutMapping("/complete/{id}")
    public Result completeOrder(@PathVariable Long id){
        log.info("【完成订单】，订单id{}",id);
        ordersService.completeOrder(id);
        return Result.success();
    }
}
